package com.zhx.factory.support;

import com.zhx.factory.BeansException;
import com.zhx.factory.config.BeanDefinition;

/**
 * @author zhx
 * @title  实例化bean，并存入缓存
 * @description
 * @date 2022/9/29 11:15
 */
public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFactory{

    @Override
    protected Object createBean(String beanName, BeanDefinition beanDefinition) throws BeansException {
        Object bean = null;
        try {
            bean = beanDefinition.getBeanClass().newInstance();
        } catch (InstantiationException | IllegalAccessException e) {
            throw new BeansException("Instantiation of bean failed", e);
        }

        addSingleton(beanName, bean);
        return bean;
    }
}
